// let sx = 247,sitem = 0;
// let stime;
let a=``;
onload = function() {
	timer2=setInterval(onclick,10000)
	clearInterval(timer2)
	let s = document.querySelector(".wrapper");
	let ss = document.querySelector(".wrapperbox");
	s.style.left = "-1519px";

	ss.onmouseover=function(){
		clearInterval(timer1)
		dax=timer2;
	}
	ss.onmouseleave=function(){
		timer1=setInterval(leftmove1,5000);
		dax=timer2;
	}
	timer1=setInterval(leftmove1,5000);
	daohanglan();
	document.querySelectorAll("#sleft").forEach(x=>{
		x.onclick = function() {
			srightmove();
		}
	})
	document.querySelectorAll("#sright").forEach(x=>{
		x.onclick = function() {
			sleftmove();
		}
	})
	document.querySelectorAll("#sjpbswrapper").forEach(x=>{
		x.style.left="5px"
	})


	document.querySelector("#search").addEventListener("keydown",keyboard)
	document.querySelector("#search").addEventListener("input",searchtips)
	document.querySelector(".searchtip").addEventListener("mouseleave",function (){
		document.querySelector(".searchtip").style.display="none"
	})

	document.querySelectorAll(".xlli").forEach(x=>{
		x.addEventListener("mouseover",xllijdbc);
	})
	a =document.querySelector(".showNavtwoson").innerHTML;
	document.querySelector(".newtuijian").addEventListener("mouseover",function (){
		document.querySelector(".showNavtwoson").innerHTML=a;
	})
	document.querySelectorAll(".gnb_nav_center").forEach(x=>{
		x.addEventListener("mouseover",function (){
			document.querySelector(".showNavtwoson").innerHTML=a;
		})
	})

	document.querySelectorAll(".xlli").forEach(x=>{
		x.addEventListener("click",function (){
			let xid = parseInt(event.target.getAttribute("id"));
			location.href="/goodsList?xid="+xid+"&show="+1;
		})
	})

	
}


function Login(){
	let login = document.querySelector("#Login");
	let levitation = document.querySelector("#levitation");

	login.onmouseenter = function (){
		levitation.style.display = "block";
	}
	levitation.onmouseleave = function (){
		levitation.style.display = "none";
	}
}


function isnull(){
	location.href="/login"
}
function iscart(){
	location.href="/goods"
}



function keyboard(){
	let keycode = event.keyCode;
	if (keycode == 13){
		search();
	}
}

function search(){
	let searchvalue = document.querySelector("#search").value;
	if(searchvalue==""){
		event.preventDefault();
	}else {
		location.href="/index?v=search&searchvalue="+searchvalue;
	}

}

function searchtips(){
	if (document.querySelector("#search").value==""){
		document.querySelector(".searchtip").style.display="none"
	}else {
		document.querySelector(".searchtip").style.display="block"
	}
	let searchvalue = document.querySelector("#search").value;
	$.ajax({
		url:"/index?v=searchtip",
		type:"post",
		data:{
			searchvalue
		},
		dataType:"json",
		success:(resp=>{
			if (resp.length>4){
				document.querySelector(".searchtip").style.height="80px";
				document.querySelector(".searchtip").style.overflowY="scroll";
			}else if (resp.length==0){
				document.querySelector(".searchtip").style.height="20px";
				document.querySelector(".searchtip").style.overflowY="";
			}else if(resp.length<4){
				document.querySelector(".searchtip").style.height="auto";
				document.querySelector(".searchtip").style.overflowY="";
			}
			let tipsbox = document.querySelector(".searchtip");
			let html=``;
			resp.forEach(r=>{
				html+=`<div onclick="bindfuture()">`+r.sname+`</div>`
			})
			tipsbox.innerHTML=html;
		})
	})
}

function bindfuture(){
	let divname = event.currentTarget.innerText;
	location.href="/index?v=search&searchvalue="+divname;
}


function xllijdbc(){
	let xid = parseInt(event.currentTarget.getAttribute("id"));
	$.ajax({
		url:"/index?v=searchli",
		type:"post",
		data:{
			xid
		},
		success:((resp)=>{
			let r = JSON.parse(resp);
			let showNavtwoson = document.querySelector(".showNavtwoson");
			let html = ``;
			r.forEach(y=>{
					html+=`<li onclick="chuandetail(${y.sid},${y.lid})">`+y.sname+`</li>`
			})
			showNavtwoson.innerHTML=html;
		})
	})
}

function chuandetail(params1,params2){
	location.href="/productDetails?sid="+params1+"&lid="+params2;
}


function daohanglan() {
	let allLi = document.querySelectorAll(".gnb_nav_center li");
	let show = document.querySelector("#show");
	let zzc = document.querySelector("#zzc");
	let img = document.querySelectorAll(".showNavone li span img");
	let showli = document.querySelectorAll(".showNavone li");
	let showNavtwoson = document.querySelector(".showNavtwoson");
	allLi.forEach(x => {
		x.addEventListener("mouseover", function() {
			document.querySelector("#show").style.height = 680 + "px";
			zzc.style.display = "block";

			showli.forEach(x => {
				x.style.fontWeight = "";
			})

			for (var i = 0; i < img.length; i++) {
				if (i == 0) {
					img[i].style.display = "block";
					document.querySelector(".showNavone li").style
						.fontWeight = "bold";
				} else {
					img[i].style.display = "none";
				}
			}
			allLi.forEach(y => {
				y.style.background = "#fff";
				y.style.color = "#000";
			})
			event.target.style.background = "#000";
			event.target.style.color = "#ffff";

			showNavtwoson.style.display="block";
		})

	})
	document.querySelector(".gnb_nav").onmouseleave = function() {
		show.style.height = 0 + "px";
		zzc.style.display = "none";
		allLi.forEach(y => {
			y.style.background = "#fff";
			y.style.color = "#000";
		})
	}

	let cancel = document.querySelector("#cancelshow");
	cancel.addEventListener("click", function() {
		show.style.height = 0 + "px";
	})

	showli.forEach(x => {
		x.addEventListener("mouseover", function() {
			img.forEach(x => {
				x.style.display = "none";
			})
			let hhh = event.currentTarget.querySelector("span img");
			hhh.style.display = "block";
			showli.forEach(y => {
				y.style.fontWeight = "";
			})
			event.currentTarget.style.fontWeight = "bold";

			showNavtwoson.style.display = "none";
			setTimeout(() => {
				showNavtwoson.style.display = "block"
			}, 150);
		})
	})
}

function sr1(){
	location.href="/productDetails?sid=7&lid=4"
}
function sr2(){
	location.href="https://shop.samsung.com.cn/activitys/TV-CseriesRegister"
}
function sr3(){
	location.href="https://shop.samsung.com.cn/activitys/galaxyA54"
}
function sr4(){
	location.href="https://shop.samsung.com.cn/activitys/memS23TV-JointPromotion"
}
function sr5(){
	location.href="https://shop.samsung.com.cn/activitys/galaxyDoubleTwelve2022CEBundle"
}
function sr6(){
	location.href="https://shop.samsung.com.cn/product/DF60A8500PG/DF60A8500PGSC"
}




let index = 1;
let displacement = 0;
var timer1=0;
var timer2;
let xz = 0;
let dax = 1;
//是否越界
var flag = false;
//图片向左移动到目标位置
function moveleft() {
	let s = document.querySelector(".wrapper");
	s.style.left = (parseInt(s.style.left) - 49) + "px"
	x += 49;
	if (x == displacement) {
		let span=document.querySelectorAll("#point_row span");

		clearInterval(timer2);
		if (flag) {
			s.style.left = "-1519px"
			flag = false;
			index = 1;
		}
		dax=timer2;
		index = (parseInt(s.style.left) / (-1519));
		bianyanse()
		for (var i = 0; i < span.length; i++) {
			if(i==index-1){
				span[i].style.background="#fff";
			}else{
				span[i].style.background="#cacaca";
			}
		}
	}
}
//图片向右移动到目标位置
function moveright() {
	let s = document.querySelector(".wrapper");
	s.style.left = (parseInt(s.style.left) + 49) + "px"
	x += 49;

	if (x == displacement) {
		let span=document.querySelectorAll("#point_row span");
		clearInterval(timer2);
		if (flag) {
			s.style.left = "-9114px"
			flag = false;
			index = 6;
		}
		dax=timer2;
		index = (parseInt(s.style.left) / (-1519));

		bianyanse()
		for (var i = 0; i < span.length; i++) {
			if(i==index-1){
				span[i].style.background="#fff";
			}else{
				span[i].style.background="#cacaca";
			}
		}
	}
}
function bianyanse(){
	var lunbotext=document.querySelector("#lunbotext");
	switch (index){
		case 1:
			lunbotext.innerHTML=`
			<p id="text1">Galaxy S23 Ultra</p>
			<p id="text2">震撼上市</p>
			<p id="text3">12期0利率 至高600元换新补贴</p>
			<p id="text4"><button onclick="sr1()">立即抢购</button></p>`
			lunbotext.style.display="block"
			lunbotext.style.color="#fff"
			break;
		case 2:
			lunbotext.innerHTML=`
			<p id="text1">三星品牌月</p>
			<p id="text2">焕新好时节</p>
			<p id="text3">画壁电视+2元享超值换购边框2个</p>
			<p id="text4"><button onclick="sr2()">立即抢购</button></p>`
			lunbotext.style.display="block"
			lunbotext.style.color="#fff"
			break;
		case 3:
			lunbotext.innerHTML=`
			<p id="text1">一线直连畅爽大屏游戏</p>
			<p id="text2">Galaxy S23系列手机</p>
			<p id="text3">画壁电视+2元享超值换购边框2个</p>
			<p id="text4"><button onclick="sr3()">立即抢购</button></p>`
			lunbotext.style.display="block"
			lunbotext.style.color="#000"
			break;
		case 4:
			lunbotext.innerHTML=`
			<p id="text1">三星品牌月</p>
			<p id="text2">焕新好时节</p>
			<p id="text3">画壁电视+2元享超值换购边框2个</p>
			<p id="text4"><button onclick="sr4()">立即抢购</button></p>`
			lunbotext.style.display="block"
			lunbotext.style.color="#000"
			break;
		case 5:
			lunbotext.innerHTML=`
			<p id="text1">三星品牌月 套购会场</p>
			<p id="text2">套装搭配购至高优惠8780元</p>
			<p id="text3">指定套装享300元优惠卷</p>
			<p id="text4"><button onclick="sr5()">立即抢购</button></p>`
			lunbotext.style.display="block"
			lunbotext.style.color="#000"
			break;
		case 6:
			lunbotext.innerHTML=`
			<p id="text1">臻智呵护 衣如初见</p>
			<p id="text2">30天无忧购 赠豪华大礼包</p>
			<p id="text3">限缤色铂格衣物护理机</p>
			<p id="text4"><button onclick="sr6()">立即抢购</button></p>`
			lunbotext.style.display="block"
			lunbotext.style.color="#fff"
			break;
	}
}
function leftmove1() {
	if (dax == timer2) {
		if (index + 1 > 6) {
			flag = true;
			move(7);
		} else {
			move(index + 1);
		}
	}
}

function rightmove1() {
	if (dax == timer2) {
		if (index - 1 < 1) {
			flag = true;
			move(0);
		} else {
			move(index - 1);
		}
	}
}

//判断是往左移,还是右移
function move(i) {
	if(dax==timer2){
		var lunbotext=document.querySelector("#lunbotext");
		if (i > index) {
			lunbotext.style.display="none";
			x = 0;
			displacement = (i - index) * 1519;
			timer2 = setInterval(moveleft, 10);
		} else if (i < index) {
			lunbotext.style.display= "none";
			x = 0;
			displacement = (index - i) * 1519;
			timer2 = setInterval(moveright, 10);
		}
	}
}
let ss;
let abc=0;
function srightmove() {
	if(event!=undefined){
		ss= event.currentTarget.parentNode.parentNode.childNodes[1];
	}
	if(parseInt(ss.style.left)==5){

	}else{
		abc+=13;
		ss.style.left =parseInt(ss.style.left)+13+"px"
		stime = setTimeout(srightmove, 10);
		if (abc % sx == 0) {
			clearTimeout(stime);
			abc=0;
		}
	}
}
function sleftmove() {
	if(event!=undefined){
		ss= event.currentTarget.parentNode.parentNode.childNodes[1];
	}
	if(parseInt(ss.style.left)==-(983)){

	}else{
		abc+=13;
		ss.style.left =parseInt(ss.style.left)-13+"px"
		stime = setTimeout(sleftmove, 10);
		if (abc % sx == 0) {
			clearTimeout(stime);
			abc=0;
		}
	}
}
